<?php namespace simpleFlow\view;

use simpleFlow\view\View as SFView;

// Include the Smarty plugins
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/Smarty.class.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_config_file_compiler.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_config_source.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_resource.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_resource_recompiled.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_resource_eval.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_config.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_compilebase.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_templatecompilerbase.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_templatelexer.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_templateparser.php');
require_once(SF_LIB_DIR_ROOT.'lib/Smarty/sysplugins/smarty_internal_write_file.php');

/**
 * View class extended of Smarty
 * @package simpleFlow
 * @subpackage view
 * @author Guilherme Fontenele
 */
class View extends \Smarty
{
	/**
	 * @var SFView View object
	 */
	public $objTheme;
	/**
	 * @var boolean If wants fetch mode
	 */
	public $booFetchMode;
	/**
	 * @todo verify if still use this!
	 * @var array Id dont know?!
	 */
	public $arrFetchMode; // TODO verify if still use this!
	
	/**
	 * Constructor
	 * @param string $strTemplateDir Templates directory
	 * @param string $strConfigDir Configs Directory
	 * @param boolean $booFetchMode If wants fetch mode
	 */
	public function __construct($strTemplateDir = '',$strConfigDir = '',$booFetchMode = false)
	{
		parent::__construct();
		$this->compile_check	= true;
		$this->debugging		= false;
		$this->setTemplateDir($strTemplateDir);
		$this->compile_dir		= SF_APP_DIR_ROOT.'.tmp/';
		$this->cache_dir		= SF_APP_DIR_ROOT.'.cache/';
		$this->config_dir		= '';
		$this->booFetchMode		= $booFetchMode;
	}
	
	/**
	 * Setters
	 * @param string $var Attribute name
	 * @param id $params Parameter
	 */
	public function __set($var,$params)
	{
		$this->assign($var,$params);
	}
	
	/**
	 * Getters
	 * @param string $var Attribute name
	 * @return id Parameter 
	 */
	public function __get($var)
	{
		if(isset($this->tpl_vars[$var]))
		{
			return $this->tpl_vars[$var];
		}else{
			return false;
		}
	}
	
	/**
	 * Defines the fetch mode on or off
	 * @param boolean $boolean If wants fetch mode
	 */
	public function setFetchMode($boolean = false)
	{
		$this->booFetchMode = $boolean;
	}
	
	/**
	 * Verify if fetch mode is active
	 * @return boolean If fetch mode is active
	 */
	public function getFetchMode() { return $this->fetchMode; }
	
	/**
	 * Return the html content of template or fetch and append it into sf_content
	 * @param string $strTemplate
	 * @return string Html content
	 */
	public function show($strTemplate)
	{
		if($this->booFetchMode)
		{
			$_strTemp = $this->fetch($strTemplate);
			return $_strTemp;
		}else{
			$_strHtml = isset($this->tpl_vars['sf_content']) ? $this->tpl_vars['sf_content'] : '';
			$this->assign('sf_content',$_strHtml.$this->fetch($strTemplate));
		}
	}
}

?>